package com.fulihui.systemcore.dal.convertor;

import java.util.List;
import java.util.stream.Collectors;

import org.near.toolkit.common.DateUtils;
import org.springframework.beans.BeanUtils;

import com.fulihui.systemcore.dal.dataobj.ProjectDO;
import com.fulihui.systemcore.dto.ProjectDTO;

/**
 * 
 * @author leeson 2016年5月17日 下午1:43:19
 *
 */
public class ProjectConv {
    private static final String[] ignore = { "gmtCreate", "gmtModified" };

    public static ProjectDO convert2DO(ProjectDTO mo_) {
        if (mo_ == null) {
            return null;
        }

        ProjectDO do_ = new ProjectDO();
        BeanUtils.copyProperties(mo_, do_, ignore);

        do_.setGmtCreate(mo_.parseGmtCreate());
        do_.setGmtModified(mo_.parseGmtModified());

        return do_;
    }

    public static ProjectDTO convert2DTO(ProjectDO do_) {
        if (do_ == null) {
            return null;
        }

        ProjectDTO mo_ = new ProjectDTO();
        BeanUtils.copyProperties(do_, mo_, ignore);

        mo_.setGmtCreate(DateUtils.formatNewFormat(do_.getGmtCreate()));
        mo_.setGmtModified(DateUtils.formatNewFormat(do_.getGmtModified()));

        return mo_;
    }

    public static List<ProjectDTO> convert2List(List<ProjectDO> list) {
        return list.stream().map((t) -> {
            return convert2DTO(t);
        }).collect(Collectors.toList());
    }
}